package rule

import (
	"regexp"
)

func init() {
	Register(&alphaDashRule{Regexp: regexp.MustCompile(`^[A-Za-z0-9\-\_]+$`)})
}

type alphaDashRule struct {
	*regexp.Regexp
}

func (a *alphaDashRule) Name() string {
	return "alphaDash"
}

func (a *alphaDashRule) Check(in *RuleInput) (err error) {
	if v, ok := in.Value.(string); ok && v != "" && a.FindStringIndex(v) != nil {
		return
	}
	return in.Error()
}
